﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Threading.Tasks;
using System.Net;
using System.Web;
using System.Web.Mvc;
using One.Models;
using OneWeb.DbContexts;

namespace OneWeb.Controllers
{
    public class SerialController : Controller
    {
        private OneDataContext db = new OneDataContext();

        // GET: Serials
        public async Task<ActionResult> Index()
        {
            var serials = db.Serials.Include(s => s.Author);
            return View(await serials.ToListAsync());
        }

        // GET: Serials/Details/5
        public async Task<ActionResult> Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Serial serial = await db.Serials.FindAsync(id);
            if (serial == null)
            {
                return HttpNotFound();
            }
            return View(serial);
        }

        //// GET: Serials/Create
        //public ActionResult Create()
        //{
        //    ViewBag.AuthorId = new SelectList(db.Authors, "Id", "Name");
        //    return View();
        //}

        //// POST: Serials/Create
        //// To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        //// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
        //[HttpPost]
        //[ValidateAntiForgeryToken]
        //public async Task<ActionResult> Create([Bind(Include = "Id,Title,Excerpt,ReadNum,MakeTime,AuthorId")] Serial serial)
        //{
        //    if (ModelState.IsValid)
        //    {
        //        db.Serials.Add(serial);
        //        await db.SaveChangesAsync();
        //        return RedirectToAction("Index");
        //    }

        //    ViewBag.AuthorId = new SelectList(db.Authors, "Id", "Name", serial.AuthorId);
        //    return View(serial);
        //}

        //// GET: Serials/Edit/5
        //public async Task<ActionResult> Edit(int? id)
        //{
        //    if (id == null)
        //    {
        //        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        //    }
        //    Serial serial = await db.Serials.FindAsync(id);
        //    if (serial == null)
        //    {
        //        return HttpNotFound();
        //    }
        //    ViewBag.AuthorId = new SelectList(db.Authors, "Id", "Name", serial.AuthorId);
        //    return View(serial);
        //}

        //// POST: Serials/Edit/5
        //// To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        //// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
        //[HttpPost]
        //[ValidateAntiForgeryToken]
        //public async Task<ActionResult> Edit([Bind(Include = "Id,Title,Excerpt,ReadNum,MakeTime,AuthorId")] Serial serial)
        //{
        //    if (ModelState.IsValid)
        //    {
        //        db.Entry(serial).State = EntityState.Modified;
        //        await db.SaveChangesAsync();
        //        return RedirectToAction("Index");
        //    }
        //    ViewBag.AuthorId = new SelectList(db.Authors, "Id", "Name", serial.AuthorId);
        //    return View(serial);
        //}

        //// GET: Serials/Delete/5
        //public async Task<ActionResult> Delete(int? id)
        //{
        //    if (id == null)
        //    {
        //        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        //    }
        //    Serial serial = await db.Serials.FindAsync(id);
        //    if (serial == null)
        //    {
        //        return HttpNotFound();
        //    }
        //    return View(serial);
        //}

        //// POST: Serials/Delete/5
        //[HttpPost, ActionName("Delete")]
        //[ValidateAntiForgeryToken]
        //public async Task<ActionResult> DeleteConfirmed(int id)
        //{
        //    Serial serial = await db.Serials.FindAsync(id);
        //    db.Serials.Remove(serial);
        //    await db.SaveChangesAsync();
        //    return RedirectToAction("Index");
        //}

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}
